package com.aya.transaction.service;

import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class BlogMandatoryTransactionService {
    @Resource
    BlogSimpleTransactionService blogSimpleTransactionService;

    @Transactional
    public void updateByIdSuccess(String id, String content, String id2, String content2) {
        blogSimpleTransactionService.updateById(id, content);
        blogSimpleTransactionService.updateByIdMandatory(id2, content2);
    }

    @Transactional
    public void updateByIdSupportFailure(String id, String content, String id2, String content2) {
        blogSimpleTransactionService.updateById(id, content);
        blogSimpleTransactionService.updateByIdMandatoryException(id2, content2);
    }

    @Transactional
    public void updateByIdCatchFailure(String id, String content, String id2, String content2) {
        blogSimpleTransactionService.updateById(id, content);
        try {
            blogSimpleTransactionService.updateByIdMandatoryException(id2, content2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void updateByIdSuccessNotTransaction(String id, String content, String id2, String content2) {
        blogSimpleTransactionService.updateById(id, content);
        blogSimpleTransactionService.updateByIdMandatory(id2, content2);
    }

    public void updateByIdSupportFailureNotTransaction(String id, String content, String id2, String content2) {
        blogSimpleTransactionService.updateById(id, content);
        blogSimpleTransactionService.updateByIdMandatoryException(id2, content2);
    }

}
